package com.etennis.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.etennis.mapper.MemberMapper;
import com.etennis.pojos.entity.Member;
import com.etennis.security.LoginUserDetails;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Resource
    private MemberMapper memberMapper;
    @Override
    public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
        LambdaQueryWrapper<Member> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(Member::getAccount,userName);
        //new Member("111","$2a$10$Nt6DOmDT9ATPkfBmgBhnUeW3J.ZOvx9ol.f/v4E6DcN43EiEIdGU6");
        Member user=memberMapper.selectOne(wrapper);
        if(Objects.isNull(user)){
            throw new RuntimeException("error");
        }
        return new LoginUserDetails(user,null);
    }
}